package main

import "blockchain"

import "fmt"

func main() {
	bc := blockchain.NewBlockChain()
	defer bc.DB.Close()
	//bc.AddBlock("zhanghang")
	iter := bc.NewIterator()
	for {
		block, err := iter.Next()
		if err != nil {
			panic(err)
		}
		//fmt.Printf("\n++++++++++当前区块高度: %d++++++++++++\n", i)
		fmt.Printf("Version: %d\n", block.Version)
		fmt.Printf("PrevHash: %x\n", block.PrevBlockHash)
		fmt.Printf("MerkleRoot:%x\n", block.MerkleRoot)
		fmt.Printf("Timestamp: %d\n", block.Timestamp)
		fmt.Printf("Bits:%d\n", block.Bits)
		fmt.Printf("Nonce:%d\n", block.Nonce)
		fmt.Printf("Hash:%x\n", block.Hash)
		fmt.Printf("Data:%s\n", block.Data)
		pow := blockchain.NewProofOfWork(block)
		fmt.Printf("IsVliad:%v\n", pow.IsValid())
		if block.PrevBlockHash == nil {
			break
		}
	}
}
